using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Awaken.CodeGen.Entities;

namespace Awaken.CodeGen.Controls
{
    public partial class ProjectListControl : System.Web.UI.UserControl
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.IsPostBack)
            {
                grid.DataSource = Project.Broker.GetAll();
                grid.DataBind();
            }
        }

        protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int index = int.Parse(e.CommandArgument.ToString());

            string id = grid.Rows[index].Cells[0].Text.ToUpper();

            GotoProject(id);
        }

        protected void GotoProject(string id)
        {
            Response.Redirect("~/Project.aspx?ProjectID=" + id);
        }

        protected void createButton_OnClick(object s, System.EventArgs e)
        {
            Project project = new Project();
            project.ProjectName = projectNameTextBox.Text;
            project.Save();

            GotoProject(project.ProjectID.ToString());
        }
    }
}